import { CategoryData, CategoryResult } from "@/types/category";
import { PageParams, PageResult } from "@/types/common";
import request from "@/utils/request";

/**
 * 分类分页查询
 * @param params 
 * @returns 
 */
export const getCategoryPageAPI = (params: PageParams & { businessId?: number, name?: string, type?: number }) => {
  return request<PageResult<CategoryResult[]>>({
    method: 'GET',
    url: '/business/category/page',
    params
  })
}
/**
 * 启用、禁用分类
 * @param status 
 * @param id 
 * @returns 
 */
export const postCategoryStatusAPI = (status: number, id: number) => {
  return request({
    method: 'POST',
    url: `/business/category/status/${status}`,
    params: { id }
  })
}
/**
 * 添加分类
 * @param id 
 * @returns 
 */
export const addCategoryAPI = (params: CategoryData) => {
  return request({
    method: 'POST',
    url: '/business/category',
    data: params
  })
}
/**
 * 根据id查询分类
 * @param id 
 * @returns 
 */
export const getCategoryAPI = (id: number) => {
  return request({
    method: 'GET',
    url: `/business/category/${id}`
  })
}
/**
 * 修改分类
 * @param categoryData 
 * @returns 
 */
export const putCategoryAPI = (categoryData: CategoryData) => {
  return request({
    method: 'PUT',
    url: '/business/category',
    data: categoryData
  })
}
/**
 * 删除分类
 * @param id 
 * @returns 
 */
export const deleteCategoryAPI = (id: number) => {
  return request({
    method: 'DELETE',
    url: '/business/category',
    params: { id }
  })
}
/**
 * 根据类型查询分类
 * @param type 
 * @returns 
 */
export const getCategoryByTypeAPI = (businessId: number, type?: number) => {
  return request({
    method: 'GET',
    url: '/business/category/list',
    params: { type, businessId }
  })
}